package example.desinpattern.p4;

import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Dynamic implements Wahaha {

    public void wahaha() {
        System.out.println("----哇哈哈----");
    }

    public static void main(String[] args) {
        Wahaha proxyInstance = (Wahaha) Proxy.newProxyInstance(Dynamic.class.getClassLoader(), Dynamic.class.getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                return method.invoke(new Dynamic(), args);
            }
        });

        proxyInstance.wahaha();
        System.out.println(proxyInstance);
    }
}
